import { SkillInfoPanel } from "../SkillInfoPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BaseProgressBar } from "../../common/BaseProgressBar";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { RuneGetWindow } from "./runeGet/RuneGetWindow";
import { GameController } from "../../../mvc/GameController";
import { BaseWindow } from "../../../../component/window/BaseWindow";
import { SkillRunePackWindow } from "./SkillRunePackWindow";
import { RuneFeedWindow } from "./RuneFeedWindow";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { RuneUtil } from "./RuneUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class SkillRuneInfoPanel
    
    export  class SkillRuneInfoPanel extends SkillInfoPanel
    {
        constructor()
        {
            super();
            this.initUI();
            this.addListeners();
            return;
        }

        public updateRunePack(): void
        {
            if (this._runeFeedWindow) 
            {
                this._runeFeedWindow.updateRunePackData();
            }
            return;
        }

        protected initUI(): void
        {
            ObjCreate.createBg(4, 4, 210, 54, this, "DisabledBg");
            var loc1=GlobalClass.getBitmap(ImagesConst.PackItemBg);
            ObjCreate.setObjAttri(loc1, 12, 14, -1, -1, this);
            this._runeItem = new BaseItem();
            ObjCreate.setObjAttri(this._runeItem, 12, 14, 36, 36, this);
            this._runeName = ObjCreate.createTextField("", 59, 13, 150, 20, this);
            this._btnBuyRune = ObjCreate.createGButton(Language.getString(44058), 135, 7, 70, 20, this, "LinkButton");
            this._btnBuyRune.toolTipData = Language.getString(44074);
            this._runeLevel = ObjCreate.createTextField("", 59, 37, 80, 20, this);
            var loc2=GlobalStyle.textFormat1;
            loc2.leading = 10;
            this._runeDesc = ObjCreate.createTextField("", 12, 66, 200, 110, this, loc2);
            this._runeDesc.wordWrap = true;
            this._runeDesc.multiline = true;
            this._noRuneTips1 = ObjCreate.createTextField(Language.getString(44023), 60, 33, 100, 20, this, GlobalStyle.textFormat6);
            var loc3=GlobalStyle.textFormat6;
            loc3.leading = 7;
            this._noRuneTips2 = ObjCreate.createTextField("", 10, 65, 203, 60, this, loc3);
            this._noRuneTips2.multiline = true;
            this._noRuneTips2.wordWrap = true;
            this._noRuneTips2.htmlText = Language.getString(44024);
            this._btnRune = ObjCreate.createGButton(Language.getString(44025), 135, 30, 70, 22, this);
            this._runeGrowPointsTips = ObjCreate.createTextField(Language.getString(44026), 12, 160, 100, 20, this, GlobalStyle.textFormat6);
            this._progressBar = new BaseProgressBar(ImagesConst.ProgressBarBg);
            this._progressBar.setSize(188, 14);
            this._progressBar.isScale = true;
            this._progressBar.progressBarClass = ImagesConst.EnergyBar;
            this._progressBar.setProgressPosition(8, 3);
            this._progressBar.setValue(0, 100, this._progressBarPer);
            ObjCreate.setObjAttri(this._progressBar, 12, 183, -1, -1, this);
            this._btnRuneFeed = ObjCreate.createGButton(Language.getString(44027), 76, 208, 70, 22, this);
            this.addChild(new GImageBitmap("PetBlessBg.png", 6, 247));
            this._btnRuneMerge = ObjCreate.createGButton(Language.getString(44028), 75, 257, 80, 30, this, "ButtonSpecial");
            var loc4;
            (loc4 = GlobalStyle.textFormat1).leading = 6;
            var loc5;
            (loc5 = ObjCreate.createTextField("", 12, 304, 210, 80, this, loc4)).multiline = true;
            loc5.wordWrap = true;
            loc5.htmlText = Language.getString(44029);
            return;
        }

        /* internal  */addListeners(): void
        {
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemovedFromStage);
            this._btnRune.addEventListener(flash.events.MouseEvent.CLICK, this.onClickRune);
            this._btnRuneFeed.addEventListener(flash.events.MouseEvent.CLICK, this.onRuneFeedClick);
            this._btnRuneMerge.addEventListener(flash.events.MouseEvent.CLICK, this.onRuneMergeClick);
            this._btnBuyRune.addEventListener(flash.events.MouseEvent.CLICK, this.onClickBuyRuneHandler);
            return;
        }

        /* internal  */onClickBuyRuneHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RuneGetShowGetWin));
            return;
        }

        /* internal  */onRemovedFromStage(arg1: Object /* flash.events.Event */): void
        {
            if (this._runePackWindow) 
            {
                this.runePackWindow.hide();
            }
            return;
        }

        /* internal  */onClickRune(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.runePackWindow.isHide) 
            {
                this.showRunePackWindow();
            }
            else 
            {
                this.runePackWindow.hide();
            }
            return;
        }

        public showRuneGetWin(): void
        {
            var loc1=null;
            if (!(this._winRuneGet == null) && !this._winRuneGet.isHide) 
            {
                this._winRuneGet.hide();
            }
            else 
            {
                if (this._winRuneGet == null) 
                {
                    this._winRuneGet = new RuneGetWindow();
                    this._winRuneGet.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.runeGetWinRemovedHandler);
                }
                this._winRuneGet.show();
                loc1 = GameController.skill.view as BaseWindow;
                this._winRuneGet.x = loc1.width + 2;
                this._winRuneGet.y = 0;
            }
            return;
        }

        /* internal  */runeGetWinRemovedHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._winRuneGet == null) 
            {
                return;
            }
            this._winRuneGet.removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.runeGetWinRemovedHandler);
            this._winRuneGet = null;
            return;
        }

        public showRunePackWindow(): void
        {
            this.runePackWindow.show();
            var loc1=GameController.skill.view as BaseWindow;
            this.runePackWindow.x = loc1.width + 2;
            this.runePackWindow.y = 0;
            return;
        }

        public hideRunePackWindow(): void
        {
            if (this._runePackWindow && !this._runePackWindow.isHide) 
            {
                this._runePackWindow.hide();
            }
            return;
        }

        /* internal  */onRuneFeedClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.runeFeedWindow.show();
            if (this._runeItem.itemData) 
            {
                this.runeFeedWindow.setSelectItemData(this._runeItem.itemData);
            }
            return;
        }

        /* internal  */onRuneMergeClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RuneShowRuneCompositionPanel));
            return;
        }

        /* internal  */get runePackWindow(): SkillRunePackWindow
        {
            if (!this._runePackWindow) 
            {
                this._runePackWindow = new SkillRunePackWindow();
            }
            return this._runePackWindow;
        }

        /* internal  */get runeFeedWindow(): RuneFeedWindow
        {
            if (!this._runeFeedWindow) 
            {
                this._runeFeedWindow = RuneFeedWindow.instance;
            }
            return this._runeFeedWindow;
        }

        public updateRuneData(arg1: int, arg2: ItemData=null): void
        {
            this.runePackWindow.relatedPos = arg1;
            var loc1=!(arg2 == null);
            this._noRuneTips1.visible = !loc1;
            this._noRuneTips2.visible = !loc1;
            this._runeItem.visible = loc1;
            this._runeName.visible = loc1;
            this._runeLevel.visible = loc1;
            this._runeDesc.visible = loc1;
            this._runeGrowPointsTips.visible = loc1;
            this._progressBar.visible = loc1;
            if (loc1 && ItemsUtil.isHolyRune(arg2)) 
            {
                this._runeGrowPointsTips.visible = false;
                this._progressBar.visible = false;
            }
            if (loc1) 
            {
                this._runeItem.itemData = arg2;
                this._runeName.text = arg2.name;
                this._runeLevel.htmlText = RuneUtil.getRuneItemLevelName(arg2);
                this._runeDesc.htmlText = RuneUtil.getRuneItemDesc(arg2);
                this._progressBar.setValue(RuneUtil.getRuneItemNowGrow(arg2), RuneUtil.getRuneUpdateNeedGrow(arg2.itemCode), this._progressBarPer);
            }
            return;
        }

        public updateBackpackRune(): void
        {
            if (this._runePackWindow) 
            {
                this.runePackWindow.updateBackpackRune();
            }
            return;
        }

        /* internal */ /* var */_noRuneTips1: Object /* flash.text.TextField */;

        /* internal */ /* var */_noRuneTips2: Object /* flash.text.TextField */;

        /* internal */ /* var */_runeItem: BaseItem;

        /* internal */ /* var */_runeName: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnBuyRune: GButton;

        /* internal */ /* var */_runeLevel: Object /* flash.text.TextField */;

        /* internal */ /* var */_runeDesc: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnRune: GButton;

        /* internal */ /* var */_progressBar: BaseProgressBar;

        /* internal */ /* var */_btnRuneFeed: GButton;

        /* internal */ /* var */_btnRuneMerge: GButton;

        /* internal */ /* var */_runePackWindow: SkillRunePackWindow;

        /* internal */ /* var */_winRuneGet: RuneGetWindow;

        /* internal */ /* var */_runeFeedWindow: RuneFeedWindow;

        /* internal */ /* var */_runeGrowPointsTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_relatedPos: int=0;

        /* internal */ /* var */_progressBarPer: number=0.904255319149;
    }
